package Map.Test;

import java.util.HashMap;
import java.util.Scanner;

/*
 * 键盘输入一个字符串，统计各字符串出现的个数
 *
 * */
public class 获取字符串中字符个数 {
    public static void main(String[] args) {
        System.out.println("请输入字符串");
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        HashMap<Character, Integer> map = new HashMap<>();
        //System.out.println(s);
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            map.put(c,0);
        }
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (map.containsKey(c)){
                Integer integer = map.get(c);
                integer++;
                map.put(c,integer);
            }
        }
        System.out.println(map);

    }

}
